package com.cskaoyan.controller.admin;

import com.cskaoyan.bean.bo.AftersaleIdBo;
import com.cskaoyan.bean.entity.Aftersale;
import com.cskaoyan.bean.vo.BasePageData;
import com.cskaoyan.bean.vo.BaseParam;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.AftersaleService;
import com.cskaoyan.utils.AftersaleStatus;
import com.cskaoyan.utils.BaseRespVoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author break_a_leg
 * @description  售后管理
 * @date 2021年10月18日 20:37
 */
@RestController
@RequestMapping("admin/aftersale")
public class AftersaleController {

    @Autowired
    AftersaleService aftersaleService;

    @RequestMapping("list")
    public BaseRespVo list(Short status, String aftersaleSn, Integer orderId, BaseParam param) {
        BasePageData data = aftersaleService.query(status,aftersaleSn,orderId,param);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("batch-recept")
    public BaseRespVo batchRecept(@RequestBody AftersaleIdBo aftersaleId) {
        Integer[] ids = aftersaleId.getIds();
        int code = aftersaleService.update(ids, AftersaleStatus.APPROVED.getCode(),AftersaleStatus.APPLIED.getCode());
        return BaseRespVoUtil.respByConstantCode(code,"当前售后状态无法审核通过");
    }

    @RequestMapping("batch-reject")
    public BaseRespVo batchReject(@RequestBody AftersaleIdBo aftersaleId) {
        Integer[] ids = aftersaleId.getIds();
        int code = aftersaleService.update(ids, AftersaleStatus.AUDIT_REJECT.getCode(),AftersaleStatus.APPLIED.getCode());
        return BaseRespVoUtil.respByConstantCode(code,"当前售后状态无法审核拒绝");
    }

    @RequestMapping("recept")
    public BaseRespVo recept(@RequestBody Aftersale aftersale) {
        Integer[] ids = new Integer[]{aftersale.getId()};
        int code = aftersaleService.update(ids,AftersaleStatus.APPROVED.getCode(),AftersaleStatus.APPLIED.getCode());
        return BaseRespVoUtil.respByConstantCode(code,"审核不通过");
    }

    @RequestMapping("reject")
    public BaseRespVo reject(@RequestBody Aftersale aftersale) {
        Integer[] ids = new Integer[]{aftersale.getId()};
        int code = aftersaleService.update(ids,AftersaleStatus.AUDIT_REJECT.getCode(),AftersaleStatus.APPLIED.getCode());
        return BaseRespVoUtil.respByConstantCode(code,"审核不通过");
    }

    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody Aftersale aftersale) {
        Integer[] ids = new Integer[]{aftersale.getId()};
        int code = aftersaleService.update(ids,AftersaleStatus.REFUND_SUCCESS.getCode(),AftersaleStatus.APPROVED.getCode());
        return BaseRespVoUtil.respByConstantCode(code,"订单退款失败");
    }
}
